<?php


namespace app\admin\controller;

use app\admin\model\DeviceOrder as DeviceOrderModel;
use app\admin\model\User as UserModel;

class DeviceOrder extends Base
{
    /***
     * 展示页面
     */
    public function lists() {
        return $this->fetch();
    }

    /***
     * layui 数据表格接口
     */
    public function get_device_order_list() {
        $device_order = new DeviceOrderModel();
        $user = new UserModel();
        //排除被删除的
//        $this->_condition['where']['deleted'] = 0;
//        $this->_condition['with'] = 'user';
        $data = $device_order->get_data_list($this->_condition);
        for ($i = 0; $i < count($data); $i++) {
            $data[$i]['start_user_name'] =  $data[$i]->user->nick_name;
            if (is_null($data[$i]['end_user_id'])) {
                $data[$i]['end_user_name'] = '';
           } else {
                $user_info = $user->where(['id'=>$data[$i]['end_user_id']])->find();
                $data[$i]['end_user_name'] = is_null($user_info) ? '' : $user_info['nick_name'];
            }
        }
        $count = $device_order->get_data_count($this->_condition['where']);
        response_json('', $data, $count);
    }
}